<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap-table.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
    <script src="../../js/bootstrap-table.min.js"></script>
    <script src="../../js/bootstrap.min.js"></script>
    <script src="../../js/bootstrap-table-zh-CN.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <style>
        #tbody input:focus{
            outline: none;
        }
    </style>
    <script>


        $(function () {
            $("#tab").bootstrapTable({
                method: "get",
                contentType: "application/json;charset=utf-8",
                url: "/scell/queryDfile",
                striped: true,
                pageNumber: 1,
                pagination: true,
                sidePagination: 'server',
                pageSize: 3,
                pageList: [3, 5, 6, 10],
                queryParams: function (params) {
                    return {
                        // 计算页号(当前页)
                        pageNumber: (params.offset / params.limit) + 1,
                        // 计算页大小
                        pageSize: params.limit,
                    }
                },
                columns: [
                    {title: '产品编号', field: 'productId', align: 'center'},
                    {title: '产品名称', field: 'productName', align: 'center'},
                    {title: '用途类型', field: 'type', align: 'center',formatter:function (value,row,index) {
                                if(value=='y001-1'){
                                    return '商品';
                                }else if(value=='y001-2'){
                                    return  '物料';
                                }else{
                                    return '未知';
                                }
                        }},
                    {title: '档次级别', field: 'productClass', align: 'center',formatter:function (value, row, index) {
                        if(value=='d001-1'){
                                return '高档';
                            }else if (value=='d001-2'){
                                return '中档';
                            }else if (value=='d001-3'){
                                return '低档';
                            }else{
                                return '未知';
                            }
                        }},
                    {title: 'I级分类', field: 'firstKindName', align: 'center'},
                    {title: 'II级分类', field: 'secondKindName', align: 'center'},
                    {title: 'III级分类', field: 'thirdKindName', align: 'center'},
                    {title: '制定',field: 'id',align: 'center',
                        formatter: function (value, row, index) {
                            var btn1="<button  class='btn btn-primary btn-sm' onclick='develop("+JSON.stringify(row)+")' data-toggle='modal' data-target='#myModal2'>制定</button>";
                            return btn1;
                        }
                    },
                ]
            })
        })
        function findAcc() {
                $.ajax({
                    type:'post',
                    url:'/SysUser/queryUser',
                    success:function (result) {
                        $("#registrar").val(result.loginId);
                    }
                })
        }
        var zdObj=null;
        function develop(data) {
            findAcc();
            zdObj=data;
            $("#kxMax").val("");
            $("#kxMin").val("");
            $("#inputname").val(data.productName);
            $("#inputid").val(data.productId);
            var date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day=date.getDate();
            let odate = date.getDate();
            let hour = date.getHours()
            let minute = date.getMinutes()
            let second = date.getSeconds()
            var dataStr=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
            $("#date").val(dataStr);
           let id= data.firstKindId+"-"+data.secondKindId+"-"+data.thirdKindId
            let name=data.firstKindName+"-"+data.secondKindName+"-"+data.thirdKindName;
            $("#tbody").html("");
            $("#tbody").append("<tr><td>" +
                data.id+"</td><td>" +
                "成品库</td><td>" +
                id+"</td><td>" +
                name+"</td><td>" +
                "<input id='Maxcount' style=\"width: 100%;\" class=\"form-control-plaintext\"></td>" +
                "</tr>")
        }
        function addScell() {
            var lg=true;
           if($("#kxMax").val()=="" || $("#kxMax").val()=="0") {
               alert("库存上限报警不能小于0");
               lg=false;
           }
            if($("#kxMin").val()=="" && $("#kxMax").val()=="0") {
                alert("库存下限报警不能小于0");
                lg=false;
            }
            if(parseInt($("#kxMin").val()) > parseInt( $("#kxMax").val())) {
                alert("库存下限不能大于库存上限");
                lg=false;
            }

            if(parseInt($("#kxMax").val()) > parseInt( $("#Maxcount").val())) {
                alert("库存上限不能大于库存数量");
                lg=false;
            }

            if(lg){
                $.ajax({
                    type:'post',
                    url: '/scell/addScell',
                    contentType: 'application/json',
                    data:JSON.stringify({
                        productId:zdObj.productId,
                        productName:zdObj.productName,
                        firstKindId:zdObj.firstKindId,
                        firstKindName:zdObj.firstKindName,
                        secondKindId:zdObj.secondKindId,
                        secondKindName:zdObj.secondKindName,
                        thirdKindId:zdObj.thirdKindId,
                        thirdKindName:zdObj.thirdKindName,
                        minAmount:$("#kxMin").val(),
                        maxAmount:$("#kxMax").val(),
                        maxCapacityAmount:$("#Maxcount").val(),
                        config:$("#config").val()  ,
                        register:$("#registrar").val(),
                        registerTime:$("#date").val(),
                    }),
                    success:function (result) {
                            if(result==1){
                                alert("保存成功");
                                $("#tab").bootstrapTable("refresh");
                            }else{
                                alert("系统繁忙，请稍后");
                            }

                    }
                })
            }

        }
    </script>
</head>
<body>
<!--<div>-->
<!--    产品编号：<input type="text" >-->
<!--    产品名称：<input type="text">-->
<!--    I级分类：<select>-->
<!--    <option value="">&#45;&#45;请选择&#45;&#45;</option>-->
<!--    <option value="1">电子</option>-->
<!--    </select>-->
<!--    II级分类：<select>-->
<!--    <option value="">&#45;&#45;请选择&#45;&#45;</option>-->
<!--    <option value="1">计算机</option>-->
<!--</select>-->
<!--    III级分类：<select>-->
<!--    <option value="">&#45;&#45;请选择&#45;&#45;</option>-->
<!--    <option value="1">服务器</option>-->
<!--</select>-->
<!--    <button>查询</button>-->
<!--</div>-->
<table id="tab" class="table">

</table>


<div class="modal fade" id="myModal2">
    <div class="modal-dialog modal-xl">
        <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
                <h4 class="modal-title" style="margin-left: 43%;">安全库存配置单</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
            </div>

            <!-- 模态框主体 -->
            <div class="modal-body">

                <div class="form-group row">

                    <label for="inputname" class="col-sm-2 col-form-label">产品名称</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="inputname" readonly>
                    </div>
                    <div class="col-2"></div>
                    <label for="inputid" class="col-sm-2 col-form-label">产品编号</label>
                    <div class="col-sm-3">
                        <input type="text   " class="form-control" id="inputid" readonly>
                    </div>
                </div>

                <div class="form-group row">

                    <label for="kxMin" class="col-sm-2 col-form-label">库存报警下限数：</label>
                    <div class="col-sm-3">
                        <input type="number" class="form-control" id="kxMin" >
                    </div>
                    <div class="col-2">
                    </div>
                    <label for="kxMax" class="col-sm-2 col-form-label">库存报警上限数：</label>
                    <div class="col-sm-3 container" >
                        <input type="number" class="form-control " id="kxMax"data-toggle="tooltip" data-placement="top" data-content="提示" >
                    </div>
                </div>

                <div class="form-group row">


<!--                    <label for="isBorN" class="col-sm-2 col-form-label">设置B/N或S/N：</label>-->
<!--                    <div class="col-sm-3">-->
<!--                        <select  class="form-control" id="isBorN">-->
<!--                            <option>是</option>-->
<!--                            <option>否</option>-->
<!--                        </select>-->
<!--                    </div>-->
<!--                    <div class="col-2"></div>-->
<!--                    <label for="design" class="col-sm-2 col-form-label">设计人：</label>-->
<!--                    <div class="col-sm-3">-->
<!--                        <input type="text" class="form-control" id="design" >-->
<!--                    </div>-->
                </div>


                <div>
                    <table class="table table-striped" border="1">
                        <thead class="table-primary ">
                        <tr>
                            <td>序号</td>
                            <td>库房名称</td>
                            <td>存储地址编号</td>
                            <td>存在地址名称</td>
                            <td>最大存储量</td>
                        </tr>
                        </thead>
                        <tbody id="tbody">
                        <tr>
                            <td>1</td>
                            <td>asd</td>
                            <td>asd</td>
                            <td>asd</td>
                            <td><input style="width: 100%;" class="form-control-plaintext"></td>
                            <td><input style="width: 100%;" class="form-control-plaintext"></td>
                            <td><input style="width: 100%;" class="form-control-plaintext"></td>
                        </tr>
                        </tbody>
                    </table>
                </div>

                <div class="form-group row">

                    <label for="registrar" class="col-sm-2 col-form-label">登记人：</label>
                    <div class="col-sm-3">
                        <input type="text" class="form-control" id="registrar" readonly>
                    </div>
                    <div class="col-2"></div>
                    <label for="date" class="col-sm-2 col-form-label">登记时间：</label>
                    <div class="col-sm-3">
                        <input type="datetime" class="form-control" id="date" >
                    </div>
                </div>

                <div class="form-group">
                    <label for="config">配置需求</label>
                    <textarea class="form-control" id="config" rows="3"></textarea>
                </div>

            </div>

            <!-- 模态框底部 -->
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal" onclick="addScell()">提交</button>
                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
            </div>

        </div>
    </div>
</div>


</body>
</html>